﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.service
{
    /// <summary>
    /// 客户服务
    /// </summary>
    public class CustomerService
    {
        
        public static List<ViewCustomerDTO> GetViewCustomerDTOs18()
        {
            return FunctionHelper.JsonDeserialization<List<ViewCustomerDTO>>(
                RestCall.httpGetMethod(URL.接口url + "/customer/getViewCustomerAll")
                );
        }
        /// <summary>
        /// 取用户积分画像
        /// </summary>
        /// <returns></returns>
        public static List<PersonaDTO> getPersonaDao()
        {
            return FunctionHelper.JsonDeserialization<List<PersonaDTO>>(
                RestCall.httpGetMethod(URL.接口url + "/customer/getPersonaDao")
                );
        }
        // <summary>
        /// 用户
        /// </summary>
        /// <param name="ci"></param>
        /// <param name="information"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static void customer置空()
        {
            Frm客户.aDDRESS_ID = 0;
            Frm客户.cUSTOMER_ID = 0;
            Frm客户.customer_countid = 0;
            Frm客户.customer_name = "";
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="ci"></param>
        /// <param name="information"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static List<CustomerInformation> createCustomer(List<CustomerInformation> ci, String information, String value)
        {
            List<CustomerInformation> customerInformation = new List<CustomerInformation>();
            customerInformation.Add(new CustomerInformation(information, value));
            customerInformation.AddRange(ci);
            return customerInformation;
        }
        /// <summary>
        /// 坚山美国订单导入创建客户用
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="orderDto"></param>
        public static void Create坚山美国Customer(String firstName, String lastName,String shopId,String sexInt)
        {
            #region 原sql文创建
        //    String FirstName = firstName;
        //    String LastName = lastName;
        //    String customer_name = FirstName + LastName;
        //    DataRow dr_customerid = SQLmtm.GetDataRow("SELECT MAX(CUSTOMER_ID) AS CUSTOMER_ID FROM a_customer_p ");
        //    int cUSTOMER_ID = Convert.ToInt32(dr_customerid["CUSTOMER_ID"]);
        //    cUSTOMER_ID++;
        //    int i1 = SQLmtm.DoInsert("a_customer_p", new string[] { "CUSTOMER_ID", "CUSTOMER_FIRST_NAME", "CUSTOMER_LAST_NAME", "MOBILE", "DEFAULT_ADDR_FLAG", "SEX_CD", "E_MAIL_URL", "DELETE_FLAG", "VERSION", "CUSTOMER_STATUS" },
        //    new string[] { cUSTOMER_ID.ToString(), FirstName, LastName, "", "0", "SEX-M_10", "", "0", "1", "CUSTOMER_SOURCE-CS_SHOP" });
        //    if (i1 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }
        //    //a_customer_fit_count_r           
        //    int i14 = SQLmtm.DoInsert("a_customer_fit_count_r", new string[] { "CUSTOMER_ID", "CUSTOMER_NAME", "SEX", "AGE", "CREATE_DATE", "DELETE_FLAG", "DEFAULT_FLAG", "DATA_COMPLETE" },
        //        new string[] { cUSTOMER_ID.ToString(), customer_name, sexInt , "0", DateTime.Now.ToUniversalTime().ToString(), "0", "1", "1" });
        //    DataRow dr_customer_countid = SQLmtm.GetDataRow("SELECT MAX(ID) AS ID FROM a_customer_fit_count_r");
        //    int customer_countid = Convert.ToInt32(dr_customer_countid["ID"]);
        //    if (i14 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }
        //    //门店客户表
        //    int i2 = SQLmtm.DoInsert("a_shop_customer_r", new string[] { "SHOP_ID", "CUSTOMER_ID" }, new string[] { shopId , cUSTOMER_ID.ToString() });
        //    if (i2 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }
        //    //身高
        //    int i3 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //        new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_09", "0", "0", customer_countid.ToString() });
        //    if (i3 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //体重
        //    int i4 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //            new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_10", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i4 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //肩宽CODE
        //    int i5 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_05", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i5 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //胸围CODE
        //    int i6 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_02", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i6 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //腰围CODE
        //    int i7 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_12", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i7 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }
        //    //臀围CODE
        //    int i8 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_03", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i8 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //身长CODE
        //    int i9 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_04", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i9 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //领围CODE
        //    int i10 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_01", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i10 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //腕围CODE
        //    int i11 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_08", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i11 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //袖长CODE
        //    int i12 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_06", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i12 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    //上臂袖肥CODE
        //    int i13 = SQLmtm.DoInsert("a_customer_fit_r", new string[] { "CUSTOMER_ID", "STYLE_CATEGORY_CD", "ITEM_CD", "ITEM_VALUE", "DELETE_FLAG", "FIT_VALUE", "FIT_COUNT_ID" },
        //new string[] { cUSTOMER_ID.ToString(), "STYLE_CATEGORY-SHIRT", "SHIRT_FITMT004", "FITMT_ITEM_07", "0", "0", customer_countid.ToString() });
        //    //cUSTOMER_FIT_ID++;
        //    if (i13 != 1)
        //    {
        //        MessageBox.Show("保存失败");
        //    }

        //    DataRow dr_addressid = SQLmtm.GetDataRow("SELECT MAX(ADDRESS_ID) AS ADDRESS_ID FROM a_customer_address_p");
        //    int aDDRESS_ID = Convert.ToInt32(dr_addressid["ADDRESS_ID"]);
        //    aDDRESS_ID++;
        //    SQLmtm.DoInsert("a_customer_address_p", new string[] { "ADDRESS_ID", "CUSTOMER_ID", "DEFAULT_ADDR_FLAG", "CONSIGNEE", "ADDRESS_PROVINCE_CD", "ADDRESS_CITY_CD", "ADDRESS_DISTRICT", "ADDRESS_DETAIL", "ZIP_CODE", "MOBILE", "DELETE_FLAG" },
        //        new string[] { aDDRESS_ID.ToString(), cUSTOMER_ID.ToString(), "1", customer_name, "", "", "", "", "", "", "0" });
        //    String listFitData = null;
        //    try
        //    {
        //        DataTable dt = SQLmtm.GetDataTable("SELECT CUSTOMER_ID,ITEM_CD,ITEM_VALUE,FIT_VALUE FROM `a_customer_fit_r` WHERE FIT_COUNT_ID='" + customer_countid.ToString() + "'");
        //        foreach (DataRow dr in dt.Rows)
        //        {
        //            listFitData = listFitData + dr["ITEM_CD"].ToString() + "-" + dr["ITEM_VALUE"].ToString() + ":" + dr["FIT_VALUE"] + ",";
        //        }
        //    }
        //    catch
        //    {
        //        MessageBox.Show("保存失败");
        //    }
        //    FitValueCalculate fvc = new FitValueCalculate(customer_countid.ToString(), listFitData);

        //    String fjsondata = Newtonsoft.Json.JsonConvert.SerializeObject(fvc);
        //    //String entryDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(class1);
        //    //RestCall.PostHttp("https://shirtmtm.com/fragsmart-mtm/customer/update/update", fjsondata);
        //    //RestCall.PostHttp("http://localhost:8080/customer/update/update", fjsondata);

        //    Frm客户.cUSTOMER_ID = cUSTOMER_ID;
        //    Frm客户.customer_name = customer_name;
        //    Frm客户.aDDRESS_ID = aDDRESS_ID;
        //    Frm客户.customer_countid = customer_countid;
#endregion
        }
    }
    public class PersonaDTO
    {
        public String mobile { get; set; }
        public String customerName { get; set; }
        public String addressProvince { get; set; }
        public String addressCity { get; set; }
        public String addressDistrict { get; set; }
        public String addressDetail { get; set; }
        public String zipCode { get; set; }
        public String remarks { get; set; }
        public String membershipType { get; set; }
        public String memberId { get; set; }   //  基础会员号
        public String customerType { get; set; }    //  会员类别
        public String responser { get; set; }   //  销售负责人
        public String saleSource { get; set; }  //  客户来源：门店，团体，抖音
        public int confirmdScore { get; set; }  //积分
        public PersonaDTO()
        {

        }
    }
}
